/**************************************************************************************
*
*	Copyright (C) 2009 - 2012 Brent Andrew O. Chua - See LICENSE.txt for more info.
*		
*	Filename	-	FactoryNativeScript.cpp
*
*	Comments	-	See FactoryNativeScript.h
*
**************************************************************************************/
#include "../Include/FactoryNativeScript.h"

namespace Pulse
{
	FactoryNativeScript::FactoryNativeScript( void )
	{

	}

	FactoryNativeScript::~FactoryNativeScript( void )
	{

	}

	BOOL FactoryNativeScript::RemoveCreator( const StringIDValue id )
	{
		auto findIter = m_creators.Find( id );

		if ( findIter != m_creators.IteratorEnd() )
		{
			m_creators.Remove( findIter );
			return TRUE;
		}

		return FALSE;
	}

	void FactoryNativeScript::ClearCreators( void )
	{
		m_creators.Clear();
	}

	_INativeScript * FactoryNativeScript::Create( const StringIDValue id, ComponentNativeScript *pComponentScript )
	{
		auto findIter = m_creators.Find( id );

		if ( findIter != m_creators.IteratorEnd() )
		{
			return findIter->second( pComponentScript );
		}

		PSX_PushWarning( "No component creator registered. Returning null." );

		return PSX_NULL;
	}

	void FactoryNativeScript::Delete( _INativeScript *pScript )
	{
		auto findIter = m_deletors.Find( pScript->GetScriptNameID() );

		if ( findIter != m_deletors.IteratorEnd() )
		{
			return findIter->second( pScript );
		}

		PSX_PushWarning( "No component deletor registered. Returning null." );
	}
}